package com.java.simple.smallspring.aop.framework.adapter;

import com.java.simple.smallspring.aop.MethodBeforeAdvice;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

/**
 * @author zhoujunlin
 * @date 2022年09月11日 20:54
 * @desc
 */
@Getter
@Setter
@NoArgsConstructor
public class MethodBeforeAdviceInterceptor implements MethodInterceptor {

    private MethodBeforeAdvice advice;

    public MethodBeforeAdviceInterceptor(MethodBeforeAdvice advice) {
        this.advice = advice;
    }

    @Override
    public Object invoke(MethodInvocation methodInvocation) throws Throwable {
        // 前置执行
        this.advice.before(methodInvocation.getMethod(), methodInvocation.getArguments(), methodInvocation.getThis());
        // 执行当前方法
        return methodInvocation.proceed();
    }
}
